<?php

require_once '../include/common.inc.php';
require_once '../include/cart.class.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}

$menu_index = 2;
$page_title = 'JANSEN';
$guide_message = 'Customer | Basic Infomation | Order';
$out_ary = array();
$alert_message = '';

$uid = $_GET['uid'];

$sql = "SELECT * FROM `cart_record` WHERE `uid` = '$uid'";		
$cart_t = $db->get_one($sql);
$_SESSION["myCart"] = array();
if (!empty($cart_t)) {
	$cart = new cart();
	$cart_g = unserialize($cart_t['cart']);
	//$cart = $cart_g;
	$_SESSION["myCart"] = $cart_g->myCart;
	$cart->update();

	
	
	$info_ary = $cart->getData();
	
    //echo "<pre>";print_r($info_ary);exit;

	$total_qty = $cart->getSortCount();
	$total_cost = $cart->getTotalCost();
    //$total_qty = $order_info['totalcount'];
    //$total_cost = $order_info['totalcost'];
    
    $all_product_info_ary = array();
    foreach ($info_ary as $pid=>$vv) {
        @list($type, $pid) = explode("_", $pid);
    	$pid_ary[] = $pid;
    	
    }
    if (!empty($pid_ary)) {
    	$pid_str = implode(",", $pid_ary);
    	$sql = "SELECT `id`, `code`, `small_pic` FROM `product` WHERE id IN (" . $pid_str . ")";
    	$query = $db->query($sql);
    	while($rs = $db->fetch_array($query)) {
    	    $all_product_info_ary[$rs['id']] = $rs;
    	}
    }
    
    $sql = "SELECT `id`, `username`, `firstname`, `lastname`, `city`, `countryid`, `type` FROM `user` WHERE `id` = '" . $uid . "'";
	$user1_ary = $db->get_one($sql);
	$money_type = $user1_ary['type'] == 1 ? "HKD" : "USD";	

    $sql = "SELECT * FROM `inventory`";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $location_info_ary[$rs['id']] = $rs['name'];
    }

    $out_str = <<<EOT
    <span id="edit_area"><table width="100%" border="0" cellspacing="1" cellpadding="1">
              <!--tr class="cartAlternatingRowB"  height="30">
              <td align="left" valign="top" class="cartHeading" colspan=7>
              <strong>OrderId</strong>: $id
              <br><strong>Customer</strong>: {$user1_ary['firstname']}  
              <br><strong>City</strong>:  {$user1_ary['city']}
              <br><strong>Country</strong>: {$COUNTRY_ARY[$user1_ary['countryid']]}
              <br><br>
              </td>
              </tr-->
              <tr class="cartAlternatingRowB"  height="30">
        						    <td align="center" valign="middle" class="cartHeading" width="40">View</td>
			    			        <td align="center" valign="middle" class="cartHeading" width="80">Sections</td>
        			    			<td align="left" valign="middle" class="cartHeading" width="80">Item No.</td>
        			    			<td align="left" valign="middle" class="cartHeading" width="140" colspan=2>Product</td>     			    			
        			    			<td align="right" valign="middle" class="cartHeading" width="60">Finish</td>    	       		
        			    			<td align="center" valign="middle" class="cartHeading" width="60">Price<br>($money_type)</td>
        			    			<td align="center" valign="middle" class="cartHeading" width="40">Qty</td>
        			    			<td align="center" valign="middle" class="cartHeading" width="80">Total<br>($money_type)</td>
        						</tr>
        						<tr><td colspan=9 bgcolor="#A5AAB0" height=1></td></tr>
EOT;

foreach ($info_ary as $k=>$v) {
    @list($type, $k, $fitemid) = explode("_", $k);
    $location = $v['intype'] == 0 ? 'Products' : $location_info_ary[$v['intype']];
    
    if (trim($all_product_info_ary[$k]['small_pic']) == "" || !file_exists("../attachments/" . $all_product_info_ary[$k]['small_pic'])) {
        $all_product_info_ary[$k]['small_pic'] = 'no_40.gif';
    }
$out_str .= <<<EOT

        			            <tr class="cartAlternatingRowB1" height=45>
        			                <td align="center" valign="middle"><img src="{$web_url}attachments/{$all_product_info_ary[$k]['small_pic']}" border="0" class="picture" width="40" height="40"></td>
			    			        <td align="center" valign="middle">$location</td>			    			
        			    			<td align="left" valign="middle">{$all_product_info_ary[$k]['code']}</td>
        			    			<td align="left" valign="middle" colspan=2>{$v['name']} </td> 
        			    			<td align="left" valign="middle">{$_finish_item[$v['fitemid']]}</td>      
        			    			<td align="center" valign="middle">{$v['price']}</td>
        			    			<td align="center" valign="middle">{$v['count']}</td>
        			    			<td align="center" valign="middle">{$v['cost']}</td>
        						</tr>

EOT;
} 
$out_str .= <<<EOT
        						<tr><td colspan=9 bgcolor="#A5AAB0" height=1></td></tr>
        						<tr>
        						  <td colspan=7 height=25 align="right"><strong>Sub Total:  </strong></td>
        						  <td colspan=1 align="center">$total_cost $money_types</td>
        						</tr>   
        						
        						
              
              <tr height=30> 
                <td colspan=2></td>
              </tr>
            </table>
            
          </span>
EOT;
} else {
	$out_str = "";
}

require_once PrintEot('a_header');
echo $out_str;
require_once PrintEot('a_footer');
?>